// pages/login/bindParent/bindParent.js
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    now: "",
    name: "",
    birthday: "",
    gender: "",
    parentId: ""
  },
  inputext: function(e) {
    var key = e.target.dataset.key;
    var value = e.detail.value;
    this.setData({
      [key]: value
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let that = this;
    that.setData({
      now: new Date().format("yyyy-MM-dd")
    })
    wx.getStorage({
      key: 'currentParent',
      success: function(res) {
        wx.removeStorageSync("currentParent");
        that.setData({
          name: res.data.name,
          identity: res.data.identity,
          parentId: res.data.stdtPantId,
          gender: res.data.gender == 1 ? "男" : "女"
        })
      },
    })

  },
  bindPickerChange(e) {
    var key = e.target.dataset.key;

    this.setData({
      [key]: e.detail.value
    })

  },
  submitForm() {
    if (!this.data.birthday) return;
    app.globalData.openId = wx.getStorageSync("openId");

    app.api.ajaxSubmit("/node/wx/tools/bindParent", {
      name: this.data.name,
      birthday: this.data.birthday,
      identity: this.data.identity,
      gender: this.data.gender,
      parentId: this.data.parentId,
      openId: wx.getStorageSync("openId"),
      studentId: app.globalData.student.studentId,
      studentNumber: app.globalData.student.studentNumber
    }).then(response => {
      if (response.data.error == 10000) {
        wx.showToast({
          title: '注册成功',
          icon: "none",
          duration: 2000
        })
        app.globalData.isBound = 1;
        wx.setStorageSync("isBound", 1);
        wx.switchTab({
          url: '/pages/homePage/homePage/homePage',
        })
      }
    }).catch(err => {

    })
  }
})